import 'dart:convert' show json;

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }

  return null;
}

class MineMsgBean {
  MineMsgBean({
    this.code,
    this.data,
  });

  factory MineMsgBean.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : MineMsgBean(
          code: asT<int>(jsonRes['code']),
          data: Data.fromJson(asT<Map<String, dynamic>>(jsonRes['data'])),
        );

  int code;
  Data data;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'code': code,
        'data': data,
      };

  @override
  String toString() {
    return json.encode(this);
  }
}

class Data {
  Data({
    this.count,
    this.next,
    this.previous,
    this.results,
  });

  factory Data.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<MineMsg> results =
        jsonRes['results'] is List ? <MineMsg>[] : null;
    if (results != null) {
      for (final dynamic item in jsonRes['results']) {
        if (item != null) {
          results.add(MineMsg.fromJson(asT<Map<String, dynamic>>(item)));
        }
      }
    }
    return Data(
      count: asT<int>(jsonRes['count']),
      next: asT<String>(jsonRes['next']),
      previous: asT<String>(jsonRes['previous']),
      results: results,
    );
  }

  int count;
  String next;
  String previous;
  List<MineMsg> results;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'count': count,
        'next': next,
        'previous': previous,
        'results': results,
      };

  @override
  String toString() {
    return json.encode(this);
  }
}

class MineMsg {
  MineMsg({
    this.id,
    this.name,
    this.portrait,
    this.landing_ct,
    this.landing_instance_id,
    this.is_read,
    this.content,
    this.add_time,
  });

  factory MineMsg.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : MineMsg(
          id: asT<int>(jsonRes['id']),
          name: asT<String>(jsonRes['name']),
          portrait: asT<String>(jsonRes['portrait']),
          landing_ct: asT<String>(jsonRes['landing_ct']),
          landing_instance_id: asT<int>(jsonRes['landing_instance_id']),
          is_read: asT<bool>(jsonRes['is_read']),
          content: asT<String>(jsonRes['content']),
          add_time: asT<String>(jsonRes['add_time']),
        );

  int id;
  String name;
  String portrait;
  String landing_ct;
  int landing_instance_id;
  bool is_read;
  String content;
  String add_time;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'id': id,
        'name': name,
        'portrait': portrait,
        'landing_ct': landing_ct,
        'landing_instance_id': landing_instance_id,
        'is_read': is_read,
        'content': content,
        'add_time': add_time,
      };

  @override
  String toString() {
    return json.encode(this);
  }
}
